package com.sx.micowell.module.login

import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.mvvm.base.data.DataBindingConfig

import com.gyf.immersionbar.ImmersionBar
import com.sx.micowell.BR
import com.sx.micowell.R
import com.sx.micowell.databinding.ActSetupPwdBinding
import com.sx.micowell.framework.app.IntentKey
import com.sx.micowell.framework.app.MyActivity
import com.sx.micowell.framework.arouth.RoutePath
import com.sx.micowell.framework.model.SetupPwdModel
import com.sx.micowell.framework.tools.EditUtils

/**
 * @author: YY
 * @time: 2021/8/3
 * @describe 设置密码
 */
@Route(path = RoutePath.SETUP_PWD)
class SetupPwdActivity: MyActivity<ActSetupPwdBinding>() {

    @Autowired(name = IntentKey.TYPE)
    @JvmField
    var type : Int = 0

    @Autowired(name = IntentKey.DATA)
    lateinit var phoneNumber: String

    @Autowired(name = IntentKey.ID)
    lateinit var verifyCode: String

    private var viewModel: SetupPwdModel? = null

    override fun initViewModel() {
        super.initViewModel()
        viewModel = getActivityScopeViewModel(SetupPwdModel::class.java)
    }

    override fun getDataBindingConfig(): DataBindingConfig {
       return DataBindingConfig(R.layout.act_setup_pwd, BR.viewModel, viewModel)
    }

    override fun initView() {
        ImmersionBar.with(this).statusBarDarkFont(true)
            .fitsSystemWindows(true).init()
        if(type == 1 || type == 2) {
            binding.tvCommit.text = "确定"
        }
    }

    override fun initData() {
        viewModel?.setData(phoneNumber, verifyCode, type)
    }

    override fun initViewObservable() {
        super.initViewObservable()

        // 密码显示状态
        viewModel?.pwdSwitchEvent?.observe(this, {
                aBoolean -> EditUtils.showHide(aBoolean, binding.editPwd)
        })

        viewModel?.confirmPwdSwitchEvent?.observe(this, {
                aBoolean -> EditUtils.showHide(aBoolean, binding.editConfirmPwd)
        })
    }
}